{include="header"}

<script type="text/javascript">
   $(document).ready(function () {
      $("#b_nuevo_sat").click(function (event) {
         event.preventDefault();
         $("#modal_nuevo_sat").modal('show');
         document.f_nuevo_sat.ac_cliente.focus();
      });
      $("#ac_cliente").autocomplete({
         serviceUrl: '{$fsc->url()}',
         paramName: 'buscar_cliente',
         onSelect: function (suggestion) {
            if (suggestion)
            {
               if (document.f_nuevo_sat.codcliente.value != suggestion.data)
               {
                  document.f_nuevo_sat.codcliente.value = suggestion.data;
               }
            }
         }
      });
   });
</script>

<div class="container-fluid" style="margin-top: 10px; margin-bottom: 10px;">
   <div class="row">
      <!-- Estos botones se muestran siempre, ocupando 2 o 6 de las 12 columnas -->
      <div class="col-lg-2 col-md-3 col-sm-4 col-xs-6">
         <a href="{$fsc->url()}" class="btn btn-sm btn-default">
            <span class="glyphicon glyphicon-refresh"></span>
         </a>
         <a href="#" id="b_nuevo_sat" class="btn btn-sm btn-success">
            <span class="glyphicon glyphicon-pencil"></span> &nbsp; Nuevo SAT
         </a>
      </div>
      <!-- Se muestra si la resolución es LG, sino se oculta -->
      <div class="col-lg-10 col-md-9 col-sm-12 col-xs-12 text-right">
         <div class="hidden-lg hidden-md"><br/></div>
         <form id="f_edita_sat" name="f_edita_sat_lg" action="{$fsc->url()}" method="post" class="form form-inline">
            <div class="form-group">
               <input type="text" class="form-control" name="buscar" size="10" placeholder="Buscar"/>
            </div>
            <div class="form-group">
               <input class="form-control datepicker" type="text" name="desde" size="10" placeholder="Desde..."/>
            </div>
            <div class="form-group">
               <input class="form-control datepicker" type="text" name="hasta" size="10" placeholder="Hasta..."/>
            </div>
            <div class="form-group">
               <select name="estado" class="form-control" onchange="this.form.submit();">
                  <option value="activos">SAT activos</option>
                  {loop="fsc->listar_estados()"}
                  <option value="{$value['id_estado']}"{if="$fsc->busqueda['estado']==$value['id_estado']"} selected{/if}>{$value['nombre_estado']}</option>
                  {/loop}
                  <option value="todos"{if="$fsc->busqueda['estado']=='todos'"} selected{/if}>Todos</option>
               </select>
            </div>
            <div class="form-group">
               <select name="orden" class="form-control" onchange="this.form.submit();">
                  <option value="nsat"{if="$fsc->busqueda['orden']=='nsat'"} selected{/if}>Orden: Nº de sat</option>
                  <option value="fcomienzo"{if="$fsc->busqueda['orden']=='fcomienzo'"} selected{/if}>Fecha de comienzo</option>
                  <option value="ffin"{if="$fsc->busqueda['orden']=='ffin'"} selected{/if}>Fecha de finalizacion</option>
                  <option value="prioridad"{if="$fsc->busqueda['orden']=='prioridad'"} selected{/if}>Prioridad</option>
               </select>
            </div>
            <button class="btn btn-sm btn-primary" type="submit" onclick="this.disabled = true; this.form.submit();">
               <span class="glyphicon glyphicon-search"></span>
            </button>
         </form>
      </div>
   </div>
</div>

{if condition="isset($_GET['codcliente'])"}
<h3 class="text-center">Registros del cliente {$_GET['codcliente']}</h3>
{/if}

<div class="table-responsive">
   <table class="table table-hover">
      <thead>
         <tr>
            <th class="text-left">N sat</th>
            <th class="text-left">Prioridad</th>
            <th class="text-left">Fecha de comienzo</th>
            <th class="text-left">Fecha de finalización</th>
            <th class="text-left">Modelo</th>
            <th class="text-left">Nombre</th>
            <th class="text-left">Telefono</th>
            <th class="text-left">Movil</th>
            <th class="text-right">Estado</th>
         </tr>
      </thead>
      {loop="fsc->resultado"}
      <tr class="clickableRow{if condition="$value->estado==5"} bg-success{/if}" href="{$value->url()}">
         <td><b>{$value->nsat}</b></td>
         <td>{$value->nombre_prioridad()}</td>
         <td>{$value->fcomienzo}</td>
         <td>{$value->ffin}</td>
         <td>{$value->modelo}</td>
         <td>{$value->nombre_cliente}</td>
         <td>{$value->telefono1_cliente}</td>
         <td>{$value->telefono2_cliente}</td>
         <td class="text-right">{$value->nombre_estado()}</td>
      </tr>
      {else}
      <tr class="bg-warning">
         <td colspan="9">Sin resultados.</td>
      </tr>
      {/loop}
   </table>
</div>

<div class="modal" id="modal_nuevo_sat">
   <div class="modal-dialog">
      <div class="modal-content">
         <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h4 class="modal-title">Nuevo SAT...</h4>
         </div>
         <div role="tabpanel">
            <ul class="nav nav-tabs nav-justified" role="tablist">
               <li role="presentation" class="active">
                  <a href="#home" aria-controls="home" role="tab" data-toggle="tab">
                     Buscar cliente
                  </a>
               </li>
               <li role="presentation">
                  <a href="#profile" aria-controls="profile" role="tab" data-toggle="tab">Nuevo cliente</a>
               </li>
            </ul>
            <div class="modal-body">
               <div class="tab-content">
                  <div role="tabpanel" class="tab-pane active" id="home" style="margin-top: 10px;">
                     <form name="f_nuevo_sat" class="form" action="index.php" method="get">
                        <input type="hidden" name="codcliente"/>
                        <input type="hidden" name="opcion" value="nuevosat"/>
                        <input type="hidden" name="page" value="{$fsc->page->name}"/>
                        <div class="input-group">
                           <input class="form-control" type="text" name="ac_cliente" id="ac_cliente" placeholder="Buscar..." autocomplete="off"/>
                           <span class="input-group-btn">
                              <button class="btn btn-sm btn-primary" type="submit" onclick="this.disabled = true;
                                    this.form.submit();">
                                 <span class="glyphicon glyphicon-search"></span>
                              </button>
                           </span>
                        </div>
                     </form>
                  </div>
                  <div role="tabpanel" class="tab-pane" id="profile">
                     <form name="f_nuevo_cliente" action="{$fsc->url()}&opcion=nuevosat" method="post" class="form">
                        <div class="form-group">
                           Nombre:
                           <input class="form-control" type="text" name="nombre" autocomplete="off"/>
                        </div>
                        <div class="form-group col-lg-6">
                           Teléfono:
                           <input class="form-control" type="text" name="telefono1" autocomplete="off"/>
                        </div>
                        <div class="form-group col-lg-6">
                           Móvil:
                           <input class="form-control" type="text" name="telefono2" autocomplete="off"/>
                        </div>
                        <div class="form-group col-lg-6">
                           <a href="{$fsc->pais->url()}">País</a>:
                           <select class="form-control" name="pais">
                              {loop="$fsc->pais->all()"}
                              <option value="{$value->codpais}"{if condition="$value->is_default()"} selected="selected"{/if}>{$value->nombre}</option>
                              {/loop}
                           </select>
                        </div>
                        <div class="form-group col-lg-6">
                           <div class="text-capitalize">{#FS_PROVINCIA#}:</div>
                           <input class="form-control" type="text" name="provincia" autocomplete="off" value="{$fsc->empresa->provincia}"/>
                        </div>
                        <div class="form-group col-lg-6">
                           Ciudad:
                           <input class="form-control" type="text" name="ciudad" autocomplete="off" value="{$fsc->empresa->ciudad}"/>
                        </div>
                        <div class="form-group col-lg-6">
                           Código Postal:
                           <input class="form-control" type="text" name="codpostal" autocomplete="off" value="{$fsc->empresa->codpostal}"/>
                        </div>
                        <div class="form-group">
                           Dirección:
                           <input class="form-control" type="text" name="direccion" value="C/ " autocomplete="off"/>
                        </div>
                        <div class="form-group">
                           {#FS_CIFNIF#}:
                           <input class="form-control" type="text" name="cifnif" autocomplete="off"/>
                        </div>
                        <div class="text-right">
                           <button class="btn btn-sm btn-primary" type="submit" onclick="this.disabled = true;
                                 this.form.submit();">
                              <span class="glyphicon glyphicon-floppy-disk"></span> &nbsp; Guardar y seleccionar
                           </button>
                        </div>
                     </form>
                  </div>
               </div>
            </div>
         </div>
      </div>
   </div>
</div>

{include="footer"}